﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

using System;
using System.Collections.Generic;
using System.Text;


namespace KSOAdmin.Core.Other
{
    public class CreateInstance
    {
        public static TService GetService<TService>() where TService : class
        {
            return typeof(TService).GetService() as TService;
        }
         
    }

    public static class ServiceProviderManagerExtension
    {
        public static object GetService(this Type serviceType)
        {
            return KSOHttpContext.Current.RequestServices.GetService(serviceType);
        }

    }
 

    public static class StaticHttpContextExtensions
    {
         //public static void AddHttpContextAccessor(this IServiceCollection services)
         //{
         //    services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
         //}
        public static IApplicationBuilder UseStaticHttpContext(this IApplicationBuilder app)
        {
            var httpContextAccessor = app.ApplicationServices.GetRequiredService<IHttpContextAccessor>();
            KSOHttpContext.Configure(httpContextAccessor);
            return app;
        }
    }

}
